package com.ruoyi.web.controller.littleRedBook;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.littleRedBook.domain.pojo.TimeLimit;
import com.ruoyi.littleRedBook.service.TimeLimitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 时间限制表 前端控制器
 * </p>
 *
 * @author
 * @since
 */
@RestController
@RequestMapping("/api/timeLimit")
public class TimeLimitController {

    @Autowired
    private TimeLimitService timeLimitService;

    /**
     * 新增时间限制
     */
    @PostMapping
    public AjaxResult add(@RequestBody TimeLimit timeLimit) {
        return timeLimitService.save(timeLimit) ? AjaxResult.success() : AjaxResult.error();
    }

    /**
     * 修改时间限制
     */
    @PutMapping
    public AjaxResult edit(@RequestBody TimeLimit timeLimit) {
        return timeLimitService.updateById(timeLimit) ? AjaxResult.success() : AjaxResult.error();
    }


    /**
     * 获取时间限制详情
     */
    @GetMapping("/{timeId}")
    public AjaxResult getInfo(@PathVariable Long timeId) {
        return AjaxResult.success(timeLimitService.getById(timeId));
    }

    /**
     * 获取时间限制列表
     */
    @GetMapping
    public AjaxResult list() {
        return AjaxResult.success(timeLimitService.list());
    }
}
